package com.cy.module;

import com.cy.ext.plugin.route.ControllerBind;
import com.cy.model.UserMapRole;
import com.jfinal.plugin.activerecord.Page;

@ControllerBind(controllerKey = "/clmp/userMapRole")
public class UserMapRoleController extends WebApiController {

    @Override
    public void index() {
        UserMapRole userMapRole = getModel(UserMapRole.class);
        int page = getParaToInt("pageIndex");
        int pageSize = getParaToInt("limit");
        Page<UserMapRole> userMapRolePage = UserMapRole.dao.paginate(page, pageSize, UserMapRole.SELECT_ALL, userMapRole);
        renderBuiPage(userMapRolePage, 200);
    }

    @Override
    public void update() {
        int id = getParaToInt();
        UserMapRole tempUserMapRole = getModel(UserMapRole.class);
        UserMapRole userMapRole = UserMapRole.dao.findById(id);
        userMapRole.cover(tempUserMapRole);

        if (userMapRole.update()) {
            renderSuccess();
        } else {
            renderFail();
        }
    }

    @Override
    public void save() {
        UserMapRole userMapRole = getModel(UserMapRole.class);
        if (userMapRole.save()) {
            renderSuccess();
        } else {
            renderFail();
        }
    }

    @Override
    public void delete() {
        String[] ids = getPara().split("-");
        for (String id : ids) {
            UserMapRole.dao.deleteById(id);
        }
        renderSuccess();
    }

}